import plugins from "./plugin"
import toolbar from "./toolbar"
import axios from "axios"
import Vue from "vue";
import {Message} from 'element-ui'

const tinymceCfg = {
  selector: "",
  icons_url: "",
  icons: "",
  height: 300,
  language_url: "",
  language: "",
  body_class: "panel-body",
  object_resizing: false,
  plugins: plugins,
  toolbar: toolbar,
  menubar: "",
  content_style: "img {max-width:100%;}",
  branding: false,
  statusbar: false,
  fontsize_formats: "12px 14px 16px 18px 24px 36px 48px 56px 72px",
  font_formats: "微软雅黑=Microsoft YaHei,Helvetica Neue,PingFang SC,sans-serif;默认字体=Verdana;苹果苹方=PingFang SC,Microsoft YaHei,sans-serif;宋体=simsun,serif;仿宋体=FangSong,serif;黑体=SimHei,sans-serif;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua,palatino;",
  end_container_on_empty_block: true,
  code_dialog_height: 450,
  code_dialog_width: 1000,
  advlist_bullet_styles: "square",
  advlist_number_styles: "default",
  powerpaste_word_import: 'merge',// 参数可以是propmt, merge, clean，效果自行切换对比
  powerpaste_html_import: 'merge',// propmt, merge, clean
  powerpaste_allow_local_images: true,
  paste_enable_default_filters:false,
  paste_webkit_styles:'all',
  paste_merge_formats:false,
  paste_convert_word_fake_lists:false,
  paste_remove_styles_if_webkit:false,
  imagetools_cors_hosts: ["shigongbang.oss-cn-hangzhou.aliyuncs.com"],
  default_link_target: "_blank",
  link_title: false,
  nonbreaking_force_tab: true, // inserting nonbreaking space &nbsp; need Nonbreaking Space Plugin
  style_formats:[
    {
      title: "行高",
      items: [
        { title: "1", block: "p", styles: { "line-height": "1.0" }},
        { title: "1.5", block: "p", styles: { "line-height": "1.5" }},
        { title: "1.75", block: "p", styles: { "line-height": "1.75" }},
        { title: "2", block: "p", styles: { "line-height": "2" }},
        { title: "3", block: "p", styles: { "line-height": "3" }},
        { title: "4", block: "p", styles: { "line-height": "4" }},
        { title: "5", block: "p", styles: { "line-height": "5" }}
      ]
    },
    {
      title: '首行缩进',
      block: 'p',
      styles: {
          'text-indent': '2em'
      }
    },
  ],
  style_formats_merge: true, // 设置行高
  convert_urls: false,
  paste_data_images: true,
  init_instance_callback: function() {},
  setup: function() {},
  // 粘贴回调
  // paste_postprocess:(arg,data)=>{
  //   console.log(arg,data,'paste');
  // },
  // 粘贴回调，data为DOM节点
  paste_postprocess:(arg,data)=>{
    Array.from(data.node.getElementsByTagName('img')).map(img=>{
      if(img.getAttribute('src').startsWith('file:///')){
        Message.closeAll()
        Message.warning('您粘贴的文本里存在本地图片，不支持解析，请单独粘贴图片')
        img.setAttribute('src','')
      }
    })
  },
  // 图片
  // urlconverter_callback: (url, node, onSave, name) => {
  //   if (node === 'img' && url.startsWith('blob:')) {
  //       // Do some custom URL conversion
  //       console.log('urlConverter:', url, node, onSave, name)
  //       tinymce.activeEditor && tinymce.activeEditor.uploadImages()
  //     }
  //     // Return new URL
  //     return url
  //   },
  images_upload_handler(blobInfo, success, failure) {
    // file_ObsUpload({
    //   file:blobInfo.blob()
    // }).then(res=>{
    //   success(res.obs_upload_data.fullUrl)
    // })
    let files = blobInfo.blob()
    Vue.prototype.bus.$emit('imgLoading',true)
    if(Object.getPrototypeOf(files).isPrototypeOf(new Blob)){
          files = new window.File([files], `image${Math.floor(Math.random()*100)}.png`, {type: files.type})
    }
    const formData = new FormData();
    formData.append("file", files);
  },
  file_picker_types: "file",
}

export default tinymceCfg
